home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Crack It!
/
Crack It!.iso
/
CONTENT
/
DISKEDIT
/
SYSRT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-09-09
|
8KB
|
264 lines
{
***
SYSRT.PAS
Initialization and Cleanup Routines
(C)Copyright Gerard Paul Java 1996
Unit Source File
This unit contains routines to initialize the screen and set the proper
related variables, as well as keyboard-related routines. This is intended
to be used for full-screen programs.
***
}
{$A+,B-,F-,I-,N-,R-,S-,V-}
unit SysRt;
interface
type
PromptType = string[64];
const
ExtKey = #0; { Extended key prefix. }
F1 = #59; { Special global keys. }
Esc = #27;
Enter = #13;
UpKey = #72;
DownKey = #80;
LeftKey = #75;
RightKey = #77;
PgUpKey = #73;
PgDnKey = #81;
HomeKey = #71;
EndKey = #79;
InsKey = #82;
DelKey = #83;
ExitKey = 'X';
AltExitKey = 'Q';
RetryKey = 'R';
KeyMarker = '^';
Null = '';
Space = ' ';
SnowCheckOn = TRUE;
SnowCheckOff = FALSE;
BreakOn = TRUE;
BreakOff = FALSE;
function GetKeyNoExt: char;
inline($30/$E4/ { XOR AH,AH }
$CD/$16); { INT $16 }
procedure WaitForKeypress;
inline($30/$E4/ { XOR AH,AH }
$CD/$16); { INT $16 }
function BIOSEquipList: word;
inline($CD/$11); { INT $11 }
procedure ScreenInit;
procedure GetInput(var Result: string;lngth: integer;var Signal: boolean);
procedure InputBox(X1,Y1,X2,Y2: byte;
Attr: byte;
Prompt: PromptType; FieldLength: byte;
var Result: string;var Signal: boolean);
procedure Beep(Freq,Dur: word);
procedure TerminateProg(ErrorLevel: byte);
implementation
uses
Crt,
ScreenRt;
type
OrigCursorType = object
ScanLines: word;
procedure Save;
procedure Restore;
end;
OrigScreenSettingsType = object
OrigMode : word;
OrigActivePage : byte;
procedure Save;
procedure Restore;
end;
var
OrigCursor : OrigCursorType;
OrigScreenSettings: OrigScreenSettingsType;
{---------------------------------------------------------------------------
OrigCursorType.Save: Saves the cursor's settings.
---------------------------------------------------------------------------}
procedure OrigCursorType.Save;
begin
inline($B4/$03/ { MOV AH,3 }
$CD/$10/ { INT $10 }
$C4/$7E/$06/ { LES DI,Self }
$26/$89/$0D); { MOV ScanLines,CX }
end;
{---------------------------------------------------------------------------
OrigCursorType.Restore: Restores the hidden cursor.
---------------------------------------------------------------------------}
procedure OrigCursorType.Restore;
begin
SetCursor(ScanLines); { Reset to original. }
end;
{---------------------------------------------------------------------------
OrigScreenSettings.Save: Saves the current screen mode and active page in
the object variable.
---------------------------------------------------------------------------}
procedure OrigScreenSettingsType.Save;
begin { proc }
OrigMode := LastMode; { Save screen mode. }
inline($B4/$0F/ { MOV AH,15 }
$CD/$10/ { INT $10 }
$C4/$7E/$06/ { LES DI,Self }
$26/$88/$7D/$02); { MOV OrigActivePage,BH }
end; { proc }
{---------------------------------------------------------------------------
OrigScreenSettings.Restore: Restores the screen to its original mode found
at startup.
---------------------------------------------------------------------------}
procedure OrigScreenSettingsType.Restore;
begin
TextMode(OrigMode); { Reset to original mode. }
inline($B4/$05/ { MOV AH,05 }
$C4/$7E/$06/ { LES DI,Self }
$26/$8A/$45/$02/ { MOV AL,OrigActivePage }
$CD/$10); { INT $10 }
end;
{--------------------------------------------------------------------------
ScreenInit: Sets the screen and snow-checking variable and sets the
proper values used by the screen save/restore routines.
--------------------------------------------------------------------------}
procedure ScreenInit;
begin
OrigScreenSettings.Save;
OrigCursor.Save;
if Lo(LastMode) = Mono then { Select proper screen mode. }
ClrScr
else
TextMode(CO80);
SetCursor($FFFF); { Hide cursor. }
Delay(100); { Allow screen settling time. }
end;
procedure GetInput(var Result: string;lngth: integer;var Signal: boolean);
var
charac: char;
savecsr: byte;
begin
Signal := FALSE;
Result:=Null;
savecsr:=wherex;
Write(StringOf(Space,Lngth));
gotoxy(savecsr,wherey);
SetCursor($0607);
repeat
charac:=UpCase(ReadKey);
case charac of
chr(8): begin
if (length(Result)>0) then
begin
Write(#8,Space,#8);
Result:=copy(Result,1,length(Result)-1);
end;
end;
Esc : Signal := TRUE;
else
if (length(Result)<lngth) and (ord(charac)>=32) then
begin
write(charac);
Result:=Result+charac;
end;
end;
until (charac = Enter) or (charac = Esc);
SetCursor($FFFF);
end;
{----------------------------------------------------------------------------
InputBox: Displays a box containing an input field where a string of a
speficied length is to be entered. Signal returns TRUE if Esc was pressed.
----------------------------------------------------------------------------}
procedure InputBox(X1,Y1,X2,Y2: byte;
Attr: byte;
Prompt: PromptType; FieldLength: byte;
var Result: string;var Signal: boolean);
begin
Window(1,1,80,25); { Revert to whole screen. }
TextAttr := BoxAttr;DrawBox(X1,Y1,X2,Y2,DoubleLine);
Window(X1+2,Y1+1,X2-1,Y2-1);
TextAttr := TextNormAttr;
Writeln;
Writeln(Prompt);
Writeln;
TextAttr := Attr;
GetInput(Result,FieldLength,Signal);
end;
{---------------------------------------------------------------------------
Beep: Beeps the speaker.
---------------------------------------------------------------------------}
procedure Beep;
begin
Sound(Freq);
Delay(Dur);
NoSound;
end;
{---------------------------------------------------------------------------
TerminateProg: Clears the screen, resets the video mode, and terminates the
program.
---------------------------------------------------------------------------}
procedure TerminateProg(ErrorLevel: byte);
begin { proc }
OrigScreenSettings.Restore;
OrigCursor.Restore;
Delay(100);
Halt(ErrorLevel); { Terminate w/ ERRORLEVEL code. }
end; { proc }
end.